// $URL: http://mingw-lib.googlecode.com/svn/trunk/working/avcodec_to_widget_9/t_box_seek_manager.cpp $
// $Rev: 316 $
// $Author: akio.miyoshi $
// $Date:: 2010-07-31 05:43:58 +0000#$

#include "t_box_seek_manager.h"

int T_Box_Seek_Manager::pendingRequest()
{
    QMutexLocker v_locker(&m_request_mutex);
    Q_UNUSED(v_locker);
    return m_request_queue.size();
}
void T_Box_Seek_Manager::enqueueRequest(int a_timing)
{
    QMutexLocker v_locker(&m_request_mutex);
    Q_UNUSED(v_locker);
    m_request_queue.enqueue(a_timing);
    this->wakeAll();
}
int T_Box_Seek_Manager::dequeueRequest()
{
    QMutexLocker v_locker(&m_request_mutex);
    Q_UNUSED(v_locker);
    if(m_request_queue.size()==0)
    {
        return -1;
    }
    int v_result(m_request_queue.last());
    m_request_queue.clear();
    return v_result;
}
qint64 T_Box_Seek_Manager::maxTiming()
{
    return m_max_timing;
}
void T_Box_Seek_Manager::registerTiming(qint64 a_timing)
{
    if(m_max_timing == LONG_LONG_MAX)
    {
        return;
    }
    if(a_timing == LONG_LONG_MAX)
    {
        m_max_timing = LONG_LONG_MAX;
    }
    else
    {
        int v_hedge = T_Box::PLAYER_HEAD_HEADGE; //FIXME: T_Box_Player_Context::PLAYER_HEAD_HEADGE
        if(a_timing>(m_max_timing+v_hedge))
        {
            m_max_timing = a_timing-v_hedge;
        }
    }
}
